package items;

import java.util.ArrayList;

public class Item
{
  private static int nextID = 0;
  private int id;
  private String name = "";
  private ArrayList<ItemState> states;
  private ItemState currentState;
  
  public Item()
  {
    this("");
  }
  
  public Item(String name)
  {
    this.id = nextID++;
    this.name = name;
    
    states = new ArrayList<ItemState>();
    currentState = new ItemState();
    states.add(currentState);
  }
  
  public ItemState createItemState()
  {
    ItemState newState = new ItemState();
    states.add(newState);
    return newState;
  }
  
  public String executeVerb(String verb)
  {
    return this.currentState.executeVerb(verb);
  }
  
  public int hashCode()
  {
    return id;
  }
  
  /**
   * @return the id
   */
  public int getId()
  {
    return id;
  }

  /**
   * @param id the id to set
   */
  public void setId(int id)
  {
    this.id = id;
  }
  
  /**
   * @return the name
   */
  public String getName()
  {
    return name;
  }

  /**
   * @param name the name to set
   */
  public void setName(String name)
  {
    this.name = name;
  }

  /**
   * @return the states
   */
  public ArrayList<ItemState> getStates()
  {
    return states;
  }
  
  /**
   * @return the currentState
   */
  public ItemState getCurrentState()
  {
    return currentState;
  }

  /**
   * @param currentState the currentState to set
   */
  public String setCurrentState(ItemState currentState)
  {
    this.currentState = currentState;
    return "";
  }
  
  /**
   * @param currentState the currentState to set
   */
  public String setCurrentState(int stateID)
  {
    for(ItemState is : states)
      if(is.getId() == stateID)
        return setCurrentState(is);
    return "";
  }
  
  public ItemState getItemState(int stateID)
  {
    for(ItemState is : states)
      if(is.getId() == stateID)
        return is;
    return null;
  }
}
